USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[WorkersAttachments-Insert]    Script Date: [[20120914065004]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914065004]]
-- Description:	Insert record into table [dbo].[WorkersAttachments]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[WorkersAttachments-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[WorkersAttachments-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[WorkersAttachments-Insert]
	/*@WorkerAttachment_RowNumber int =Null OUTPUT , 
	@WorkerAttachment_ID uniqueidentifier =Null  , 
	@Worker_ID uniqueidentifier =Null  , 
	@File_DisplayName varchar(100) =Null  , 
	@File_Path varchar(max) =Null  , 
	@Is_Encrypted tinyint =0  , 
	@File_Bytes varbinary =Null  , 
	@File_Notes varchar(max) =Null  , 
	@File_Search varchar(max) =Null  , 
	@Mime_ID uniqueidentifier =Null  , 
	@WorkerAttachment_TimeStamp timestamp =Null OUTPUT*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[WorkersAttachments](/*[WorkerAttachment_ID], [Worker_ID], [File_DisplayName], [File_Path], [Is_Encrypted], [File_Bytes], [File_Notes], [File_Search], [Mime_ID]*/)
	VALUES     (/*@WorkerAttachment_ID, @Worker_ID, @File_DisplayName, @File_Path, @Is_Encrypted, @File_Bytes, @File_Notes, @File_Search, @Mime_ID*/)

	/*SELECT @WorkerAttachment_RowNumber = [WorkerAttachment_RowNumber], @WorkerAttachment_TimeStamp = [WorkerAttachment_TimeStamp]
    FROM [dbo].[WorkersAttachments]
    WHERE  ( [WorkerAttachment_ID] =@WorkerAttachment_ID )
	AND  ( [Worker_ID] =@Worker_ID )
	AND  ( [File_DisplayName] =@File_DisplayName )
	AND  ( [File_Path] =@File_Path )
	AND  ( [Is_Encrypted] =@Is_Encrypted )
	AND  ( [File_Bytes] =@File_Bytes )
	AND  ( [File_Notes] =@File_Notes )
	AND  ( [File_Search] =@File_Search )
	AND  ( [Mime_ID] =@Mime_ID )*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[WorkersAttachments-update]    Script Date: [[20120914065004]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914065004]]
-- Description:	Update record in table [dbo].[WorkersAttachments]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[WorkersAttachments-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[WorkersAttachments-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[WorkersAttachments-update]
	/*@WorkerAttachment_RowNumber int =Null OUTPUT , 
	@WorkerAttachment_ID uniqueidentifier =Null  , 
	@Worker_ID uniqueidentifier =Null  , 
	@File_DisplayName varchar(100) =Null  , 
	@File_Path varchar(max) =Null  , 
	@Is_Encrypted tinyint =0  , 
	@File_Bytes varbinary =Null  , 
	@File_Notes varchar(max) =Null  , 
	@File_Search varchar(max) =Null  , 
	@Mime_ID uniqueidentifier =Null  , 
	@WorkerAttachment_TimeStamp timestamp =Null OUTPUT , 
	@OldTimeStamp timeStamp OUTPUT*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/*SELECT @OldTimeStamp = [WorkerAttachment_TimeStamp]
    FROM [dbo].[WorkersAttachments]
    	WHERE ([WorkerAttachment_ID] = @WorkerAttachment_ID)

    IF  @OldTimeStamp = @WorkerAttachment_TimeStamp
    BEGIN*/
		Update [dbo].[WorkersAttachments] SET 
		/*[WorkerAttachment_ID] =@WorkerAttachment_ID, 
		[Worker_ID] =@Worker_ID, 
		[File_DisplayName] =@File_DisplayName, 
		[File_Path] =@File_Path, 
		[Is_Encrypted] =@Is_Encrypted, 
		[File_Bytes] =@File_Bytes, 
		[File_Notes] =@File_Notes, 
		[File_Search] =@File_Search, 
		[Mime_ID] =@Mime_ID*/
		/*WHERE ([WorkerAttachment_ID] = @WorkerAttachment_ID)*/
	/*END*/

	/*SELECT @WorkerAttachment_RowNumber = [WorkerAttachment_RowNumber], @WorkerAttachment_TimeStamp = [WorkerAttachment_TimeStamp]
    FROM [dbo].[WorkersAttachments]
	WHERE ([WorkerAttachment_ID] = @WorkerAttachment_ID)*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[WorkersAttachments-Insert-Update]    Script Date: [[20120914065004]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914065004]]
-- Description:	Insert OR Update record into table [dbo].[WorkersAttachments]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[WorkersAttachments-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[WorkersAttachments-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[WorkersAttachments-Insert-Update]
	/*@WorkerAttachment_RowNumber int =Null OUTPUT , 
	@WorkerAttachment_ID uniqueidentifier =Null  , 
	@Worker_ID uniqueidentifier =Null  , 
	@File_DisplayName varchar(100) =Null  , 
	@File_Path varchar(max) =Null  , 
	@Is_Encrypted tinyint =0  , 
	@File_Bytes varbinary =Null  , 
	@File_Notes varchar(max) =Null  , 
	@File_Search varchar(max) =Null  , 
	@Mime_ID uniqueidentifier =Null  , 
	@WorkerAttachment_TimeStamp timestamp =Null OUTPUT , 
	@Inserted bit OUTPUT , 
	@OldTimeStamp timeStamp OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[WorkersAttachments] 
					/*WHERE ([WorkerAttachment_ID] = @WorkerAttachment_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[WorkersAttachments](/*[WorkerAttachment_ID], [Worker_ID], [File_DisplayName], [File_Path], [Is_Encrypted], [File_Bytes], [File_Notes], [File_Search], [Mime_ID]*/)
		VALUES     (/*@WorkerAttachment_ID, @Worker_ID, @File_DisplayName, @File_Path, @Is_Encrypted, @File_Bytes, @File_Notes, @File_Search, @Mime_ID*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/*SELECT @OldTimeStamp = [WorkerAttachment_TimeStamp]
		FROM [dbo].[WorkersAttachments]
    	WHERE ([WorkerAttachment_ID] = @WorkerAttachment_ID)

		IF  @OldTimeStamp = @WorkerAttachment_TimeStamp
		BEGIN*/
			Update [dbo].[WorkersAttachments] SET 
			/*[WorkerAttachment_ID] =@WorkerAttachment_ID, 
			[Worker_ID] =@Worker_ID, 
			[File_DisplayName] =@File_DisplayName, 
			[File_Path] =@File_Path, 
			[Is_Encrypted] =@Is_Encrypted, 
			[File_Bytes] =@File_Bytes, 
			[File_Notes] =@File_Notes, 
			[File_Search] =@File_Search, 
			[Mime_ID] =@Mime_ID*/
			/*WHERE ([WorkerAttachment_ID] = @WorkerAttachment_ID)*/
		/*END*/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @WorkerAttachment_RowNumber = [WorkerAttachment_RowNumber], @WorkerAttachment_TimeStamp = [WorkerAttachment_TimeStamp]
    FROM [dbo].[WorkersAttachments]
	WHERE ([WorkerAttachment_ID] = @WorkerAttachment_ID)*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[WorkersAttachments-Delete]    Script Date: [[20120914065004]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914065004]]
-- Description:	delete records from table [dbo].[WorkersAttachments] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[WorkersAttachments-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[WorkersAttachments-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[WorkersAttachments-Delete]
	/*@WorkerAttachment_RowNumber int =null  , 
	@WorkerAttachment_ID uniqueidentifier =null  , 
	@Worker_ID uniqueidentifier =null  , 
	@File_DisplayName varchar(100) =null  , 
	@File_Path varchar(max) =null  , 
	@Is_Encrypted tinyint =null  , 
	@File_Bytes varbinary =null  , 
	@File_Notes varchar(max) =null  , 
	@File_Search varchar(max) =null  , 
	@Mime_ID uniqueidentifier =null  , 
	@WorkerAttachment_TimeStamp timestamp =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[WorkersAttachments]
	WHERE /*( [WorkerAttachment_RowNumber] = ISNULL(@WorkerAttachment_RowNumber, [WorkerAttachment_RowNumber]) )
	AND ( [WorkerAttachment_ID] = ISNULL(@WorkerAttachment_ID, [WorkerAttachment_ID]) )
	AND ( [Worker_ID] = ISNULL(@Worker_ID, [Worker_ID]) )
	AND ( [File_DisplayName] like ISNULL(@File_DisplayName, [File_DisplayName]) )
	AND ( [File_Path] like ISNULL(@File_Path, [File_Path]) )
	AND ( [Is_Encrypted] = ISNULL(@Is_Encrypted, [Is_Encrypted]) )
	AND ( [File_Bytes] = ISNULL(@File_Bytes, [File_Bytes]) )
	AND ( [File_Notes] like ISNULL(@File_Notes, [File_Notes]) )
	AND ( [File_Search] like ISNULL(@File_Search, [File_Search]) )
	AND ( [Mime_ID] = ISNULL(@Mime_ID, [Mime_ID]) )
	AND ( [WorkerAttachment_TimeStamp] = ISNULL(@WorkerAttachment_TimeStamp, [WorkerAttachment_TimeStamp]) )*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[WorkersAttachments-Select]    Script Date: [[20120914065004]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914065004]]
-- Description:	select records from table [dbo].[WorkersAttachments] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[WorkersAttachments-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[WorkersAttachments-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[WorkersAttachments-Select]
	/*@WorkerAttachment_RowNumber int =null  , 
	@WorkerAttachment_ID uniqueidentifier =null  , 
	@Worker_ID uniqueidentifier =null  , 
	@File_DisplayName varchar(100) =null  , 
	@File_Path varchar(max) =null  , 
	@Is_Encrypted tinyint =null  , 
	@File_Bytes varbinary =null  , 
	@File_Notes varchar(max) =null  , 
	@File_Search varchar(max) =null  , 
	@Mime_ID uniqueidentifier =null  , 
	@WorkerAttachment_TimeStamp timestamp =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[WorkersAttachments]
	WHERE /*( [WorkerAttachment_RowNumber] = ISNULL(@WorkerAttachment_RowNumber, [WorkerAttachment_RowNumber]) )
	AND ( [WorkerAttachment_ID] = ISNULL(@WorkerAttachment_ID, [WorkerAttachment_ID]) )
	AND ( [Worker_ID] = ISNULL(@Worker_ID, [Worker_ID]) )
	AND ( [File_DisplayName] like ISNULL(@File_DisplayName, [File_DisplayName]) )
	AND ( [File_Path] like ISNULL(@File_Path, [File_Path]) )
	AND ( [Is_Encrypted] = ISNULL(@Is_Encrypted, [Is_Encrypted]) )
	AND ( [File_Bytes] = ISNULL(@File_Bytes, [File_Bytes]) )
	AND ( [File_Notes] like ISNULL(@File_Notes, [File_Notes]) )
	AND ( [File_Search] like ISNULL(@File_Search, [File_Search]) )
	AND ( [Mime_ID] = ISNULL(@Mime_ID, [Mime_ID]) )
	AND ( [WorkerAttachment_TimeStamp] = ISNULL(@WorkerAttachment_TimeStamp, [WorkerAttachment_TimeStamp]) )*/
END
GO
-- =============================================
